package com.gxuwz.medical.domain.chronicdisApply;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.PreparedStatement;

import com.gxuwz.medical.database.DbUtil;

/*
 * 慢性病报销
 */
public class ChronicdisApply {
	private int id;
	private String idcard;
	private String name;
	private BigDecimal applyAcount;
	private String createtime;
	private String chronicname;
	
	public String getIdcard() {
		return idcard;
	}
	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
	public BigDecimal getApplyAcount() {
		return applyAcount;
	}
	public void setApplyAcount(BigDecimal applyAcount) {
		this.applyAcount = applyAcount;
	}
	public String getCreatetime() {
		return createtime;
	}
	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}
	
	public String getChronicname() {
		return chronicname;
	}
	public void setChronicname(String chronicname) {
		this.chronicname = chronicname;
	}
	
	
	
	public ChronicdisApply(String idcard, String name, BigDecimal applyAcount,
			String createtime, String chronicname) {
		super();
		this.idcard = idcard;
		this.name = name;
		this.applyAcount = applyAcount;
		this.createtime = createtime;
		this.chronicname = chronicname;
	}
	
	/**
	 * 添加数据进数据库
	 * @throws SQLException
	 */
	public void add() throws SQLException{
		Connection conn = null;
		try{
			conn = DbUtil.getConn();
			conn.setAutoCommit(false);
			saveToDB(conn);
			conn.commit();
		}catch(SQLException e){
			conn.rollback();
			throw(e);
		}finally{
			DbUtil.close(conn);
		}
	}
	
	private void saveToDB(Connection conn){
		PreparedStatement pstmt = null;
		try{
			StringBuffer sqlBuffer = new StringBuffer("insert into t_chronicdis_apply(idcard,applyAcount,name,chronicname,createtime)");
			sqlBuffer.append("VALUES ( ?, ? , ? , ? , ?)");
			pstmt = conn.prepareStatement(sqlBuffer.toString());
			int index = 1;
			pstmt.setString(index++, this.idcard);
			pstmt.setBigDecimal(index++,this.applyAcount);
			pstmt.setString(index++, this.name);
			pstmt.setString(index++, this.chronicname);
			pstmt.setString(index++, this.createtime);
			int c = pstmt.executeUpdate();
			System.out.println("插入了"+c+"条数据");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			DbUtil.close(pstmt);
		}
	}

	
	
	

}
